package common

import (
	"fmt"
	"strings"

	sm3 "github.com/tjfoc/gmsm/sm3"
)

//国密SM3
func SM3(data string) string {
	h := sm3.New()
	h.Write([]byte(data))
	sum := h.Sum(nil)

	return byteToString(sum)

}

// 二进制转换为字符串类型
func byteToString(b []byte) string {
	str := ""
	for i := 0; i < len(b); i++ {
		str += fmt.Sprintf("%02x", b[i])
	}
	return strings.ToUpper(str)
}
